﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ADONETDataServicesExtension.BLLUtils;

namespace BLL
{
    public class Employee : EmployeeBase
    {
        public Employee()
        {
        }
        public Employee(EFEntities.Employee employee)
            : base(employee)
        {
        }
        protected Employee(EmployeeBase employee)
            : base(employee)
        {
        }

        private Manager _manager;
        [EFEntityProperty]
        public Manager Manager
        {
            get
            {
                if (_manager == null)
                    if (EFEmployee.Manager != null)
                        _manager = new Manager(EFEmployee.Manager);
                return _manager;
            }
            set
            {
                _manager = value;
                if (value != null)
                    EFEmployee.SetManagerReference(value.Id);
            }
        }

        private Team _team;
        [EFEntityProperty]
        public Team Team
        {
            get
            {
                if (_team == null)
                    if (EFEmployee.Team != null)
                        _team = new Team(EFEmployee.Team);
                return _team;
            }
            set
            {
                _team = value;
                if (value != null)
                    EFEmployee.SetTeamReference(value.Id);
            }
        }

        private IEnumerable<Role> _roles;
        [EFEntityProperty]
        public IEnumerable<Role> Roles
        {
            get
            {
                if (_roles == null)
                    _roles = EFEmployee.Roles.AsEnumerable().Select(e => new Role(e));
                return _roles;
            }
        }
    }
}
